home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / pysmb.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  5KB  |  143 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import errno
  5. from gettext import gettext as _
  6. import gobject
  7. import gtk
  8. import os
  9. import pwd
  10. import smbc
  11. from debug import *
  12.  
  13. class AuthContext:
  14.     
  15.     def __init__(self, parent = None, workgroup = '', user = '', passwd = ''):
  16.         self.passes = 0
  17.         self.has_failed = False
  18.         self.auth_called = False
  19.         self.tried_guest = False
  20.         self.cancel = False
  21.         self.use_user = user
  22.         self.use_password = passwd
  23.         self.use_workgroup = workgroup
  24.         self.dialog_shown = False
  25.         self.parent = parent
  26.  
  27.     
  28.     def perform_authentication(self):
  29.         self.passes += 1
  30.         if self.passes == 1:
  31.             return 1
  32.         if not self.has_failed:
  33.             return 0
  34.         debugprint('pysmb: authentication pass: %d' % self.passes)
  35.         if not self.auth_called:
  36.             debugprint('pysmb: auth callback not called?!')
  37.             self.cancel = True
  38.             return 0
  39.         self.has_failed = False
  40.         if self.auth_called and not (self.tried_guest):
  41.             self.use_user = 'guest'
  42.             self.use_password = ''
  43.             self.tried_guest = True
  44.             debugprint('pysmb: try auth as guest')
  45.             return 1
  46.         self.auth_called = False
  47.         d = gtk.Dialog('Authentication', self.parent, gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
  48.         d.set_default_response(gtk.RESPONSE_OK)
  49.         d.set_border_width(6)
  50.         d.set_resizable(False)
  51.         hbox = gtk.HBox(False, 12)
  52.         hbox.set_border_width(6)
  53.         image = gtk.Image()
  54.         image.set_from_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_DIALOG)
  55.         hbox.pack_start(image, False, False, 0)
  56.         vbox = gtk.VBox(False, 12)
  57.         label = gtk.Label('<span weight="bold" size="larger">' + 'You must log in to access %s.' % self.for_server + '</span>')
  58.         label.set_use_markup(True)
  59.         label.set_alignment(0, 0)
  60.         label.set_line_wrap(True)
  61.         vbox.pack_start(label, False, False, 0)
  62.         table = gtk.Table(3, 2)
  63.         table.set_row_spacings(6)
  64.         table.set_col_spacings(6)
  65.         table.attach(gtk.Label('Username:'), 0, 1, 0, 1, 0, 0)
  66.         username_entry = gtk.Entry()
  67.         table.attach(username_entry, 1, 2, 0, 1, 0, 0)
  68.         table.attach(gtk.Label('Domain:'), 0, 1, 1, 2, 0, 0)
  69.         domain_entry = gtk.Entry()
  70.         table.attach(domain_entry, 1, 2, 1, 2, 0, 0)
  71.         table.attach(gtk.Label('Password:'), 0, 1, 2, 3, 0, 0)
  72.         password_entry = gtk.Entry()
  73.         password_entry.set_activates_default(True)
  74.         password_entry.set_visibility(False)
  75.         table.attach(password_entry, 1, 2, 2, 3, 0, 0)
  76.         vbox.pack_start(table, False, False, 0)
  77.         hbox.pack_start(vbox, False, False, 0)
  78.         d.vbox.pack_start(hbox)
  79.         self.dialog_shown = True
  80.         d.show_all()
  81.         d.show_now()
  82.         username_entry.set_text(self.use_user)
  83.         domain_entry.set_text(self.use_workgroup)
  84.         d.set_keep_above(True)
  85.         gtk.gdk.pointer_grab(d.window, True)
  86.         gtk.gdk.keyboard_grab(d.window, True)
  87.         response = d.run()
  88.         gtk.gdk.keyboard_ungrab()
  89.         gtk.gdk.pointer_ungrab()
  90.         if response == gtk.RESPONSE_CANCEL:
  91.             self.cancel = True
  92.             d.destroy()
  93.             return -1
  94.         self.use_user = username_entry.get_text()
  95.         self.use_password = password_entry.get_text()
  96.         self.use_workgroup = domain_entry.get_text()
  97.         d.destroy()
  98.         return 1
  99.  
  100.     
  101.     def initial_authentication(self):
  102.         
  103.         try:
  104.             context = smbc.Context()
  105.             self.use_workgroup = context.workgroup
  106.         except:
  107.             pass
  108.  
  109.  
  110.     
  111.     def failed(self, exc = None):
  112.         self.has_failed = True
  113.         debugprint('pysmb: operation failed: %s' % repr(exc))
  114.         if exc:
  115.             if (self.cancel or type(exc) == RuntimeError) and exc.args[0] not in [
  116.                 errno.EACCES,
  117.                 errno.EPERM]:
  118.                 raise exc
  119.             exc.args[0] not in [
  120.                 errno.EACCES,
  121.                 errno.EPERM]
  122.         
  123.  
  124.     
  125.     def callback(self, server, share, workgroup, user, password):
  126.         debugprint('pysmb: got password callback')
  127.         self.auth_called = True
  128.         self.for_server = server
  129.         self.for_share = share
  130.         if self.passes == 1:
  131.             self.initial_authentication()
  132.         
  133.         if self.use_user:
  134.             if self.use_workgroup:
  135.                 workgroup = self.use_workgroup
  136.             
  137.             return (workgroup, self.use_user, self.use_password)
  138.         user = ''
  139.         password = ''
  140.         return (workgroup, user, password)
  141.  
  142.  
  143.